<template>
  <div id="home">
    <el-row>
      <el-col style="background:#fff;border-radius:5px;margin:20px; padding:0 20px;width: calc(100% - 20px);height:810px">
        <h1><i class="index_icon index_icon_cygn"></i>功能列表</h1>
        <ul class="list_cygn" v-if="isShhUser!==null">
          <li v-if="isShhUser===false&&youngState===0"><router-link :to="{ name: 'youngCadresDept', params: {theYear} }" class="list_cygn_2" exact>优秀年轻干部</router-link></li>
          <li v-if="isShhUser===false&&unitReportNum" ><router-link :to="{ name: 'unitReportProjectList' }" class="list_cygn_3" exact>统计填报</router-link></li>
          <li v-if="isShhUser===false&&showFileDistribution"><router-link :to="{ name: 'unitFileDistributionList' }" class="list_cygn_1" exact>资料下发</router-link></li>
          <li v-if="isShhUser===true&&shenghuohuiList&&shenghuohuiList.length>0"><router-link :to="{ name: 'unitShenghuohuiList' }" class="list_cygn_4" exact>民主生活会数据填报</router-link></li>
          <li><router-link v-if="recruitFlag" :to="{ name: 'recruitUnitProjectList' }" class="list_cygn_5" exact>公开招聘</router-link></li>
          <li v-if="ver==='dev'&&postUnitId"><router-link :to="{ name: 'postUnitMain' }" class="list_cygn_6" exact>岗位设置</router-link></li>
          <li v-if="ver==='dev'&&salaryUnitId"><router-link :to="{ name: 'salaryUnitMain' }" class="list_cygn_7" exact>工资管理</router-link></li>
          <!-- <template v-if="ver==='dev'"></template> -->
          <li v-if="currentUnitStatus.status===0 && currentUnitStatus.jgsyCode"><router-link :to="{ name: 'staffingUnitOrg', query: {flag: 'user'} }" class="list_cygn_8" exact>机构编制管理</router-link></li>
          <el-tooltip v-if="currentUnitStatus.status===0 && !currentUnitStatus.jgsyCode" content="编制实名制系统未匹配到该单位数据，机构编制管理无法填报" placement="top">
            <li><a class="list_cygn_8" exact style=" filter:Gray; -webkit-filter: grayscale(100%);color:#999">机构编制管理</a></li>
          </el-tooltip>
          <!-- 临时屏蔽单位填报 -->
        </ul>
      </el-col>
    </el-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      ver: '',
      recruitFlag: false,
      isShhUser: null,
      shenghuohuiList: [],
      showFileDistribution: 0,
      youngState: '',
      archiveNum: 0,
      tasknum: 0,
      userRoles: '',
      news: [],
      listLoading: false,
      myoptionbar: {
        type: Object
      },
      myoptionpie: {
        type: Object
      },
      myoptionpie2: {
        type: Object
      },
      zhengzaibanli: '-',
      xiangguan: '-',
      unitReportNum: 0,
      postUnitId: null,
      salaryUnitId: null,
      theYear: '',
      currentUnitStatus: {}
    }
  },
  methods: {
    // 获取机构编制管理填报状态
    getCurrentUnitStatus () {
      this.$http
        .get(this.$http.defaults.headcountAPI + `api/busUnit/getCurrentUnitStatus`)
        .then(response => {
          if (response.data.success === true) {
            this.currentUnitStatus = response.data.result
          } else {
            console.log('获取失败:' + response.data.message)
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          console.log(error)
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getPostUnitId () {
      this.$http.get(this.$http.defaults.postAPI + `api/cadrePostBusUnit/getCurrentUnitId`).then(response => {
        if (response.data.success === true) {
          this.postUnitId = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      })
    },
    getSalaryUnitId () {
      this.$http.get(this.$http.defaults.salaryAPI + `api/salaryBusUnit/getCurrentUnitId`).then(response => {
        if (response.data.success === true) {
          this.salaryUnitId = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      })
    },
    getShhTopFlow () {
      this.$http.post(this.$http.defaults.shenghuohuiAPI + `api/newFlow/getCurrentTopFlows`, {}).then(response => {
        if (response.data.success === true) {
          this.shenghuohuiList = response.data.result
        } else {
          console.log('获取失败:' + response.data.message)
          this.$message({
            message: '获取失败:' + response.data.message,
            type: 'error'
          })
        }
      })
    },
    getFileDistribution () {
      let para = {
        pageNum: 1,
        pageSize: 10
      }
      this.listLoading = true
      // var personParams = { Page: 0, Pagenum: 20, Personname: '', Unitkey: '', Sortkey: '', Isace: true, timestamp: new Date().getTime() }
      this.$http
        .post(this.$http.defaults.fileDistributionAPI + `api/busArticle/queryByPage`, para)
        .then(response => {
          this.showFileDistribution = response.data.result.total
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getunitinfo () {
      this.$http
        .get(this.$http.defaults.youngAPI + `api/busUnit/getCurrentState`)
        .then(response => {
          if (response.data.success) {
            if (response.data.result) {
              localStorage.setItem('Otherunitid', response.data.result.unitId)
              localStorage.setItem('youngUnitName', response.data.result.unitName)
              this.youngState = response.data.result.state
              this.theYear = response.data.result.theYear
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          if (error.status === 500) {
            this.$message({
              message: '网络获取失败:' + error,
              type: 'error'
            })
          }
        })
    },
    getRecruitYear () {
      this.$http
        .get(this.$http.defaults.recruitAPI + `api/recruitBusAuth/currentYear`)
        .then(response => {
          if (response.data.result) {
            this.recruitFlag = true
          } else {
            this.recruitFlag = false
          }
        })
        .catch(error => {
          this.$message({
            message: '获取失败:' + error,
            type: 'error'
          })
        })
    },
    getIsShhUser () {
      this.$http
        .get(this.$http.defaults.shenghuohuiAPI + `api/home/isShhUser`)
        .then(response => {
          if (response.data.success) {
            this.isShhUser = response.data.result
            if (response.data.result) {
              this.getShhTopFlow()
              this.recruitFlag = false
            } else {
              this.getunitinfo()
              this.getUnitReport()
              this.getFileDistribution()
              this.getRecruitYear()
              this.getCurrentUnitStatus()
              if (this.ver === 'dev') {
                this.getPostUnitId()
                this.getSalaryUnitId()
              }
            }
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          if (error.status === 500) {
            this.$message({
              message: '网络获取失败:' + error,
              type: 'error'
            })
          }
        })
    },
    getUnitReport () {
      let para = {
        pageNum: 1,
        pageSize: 100
      }
      this.listLoading = true
      this.$http
        .post(this.$http.defaults.unitReportAPI + `api/project/queryTodoProjectPage`, para)
        .then(response => {
          if (response.data.success) {
            this.unitReportNum = response.data.result.records.length
          } else {
            this.$message({
              message: '获取失败:' + response.data.message,
              type: 'error'
            })
          }
        })
        .catch(error => {
          this.$message({
            message: '网络获取失败:' + error,
            type: 'error'
          })
        })
    }
  },
  mounted () {
    this.ver = document.querySelector('meta[name="ver"]').content
    this.getIsShhUser()
    this.userRoles = JSON.parse(localStorage.getItem('Roles'))
    console.log('this.userRoles')
    console.log(this.userRoles)
    // 临时屏蔽单位填报
  }
}
</script>
<style scoped>
h1{
  color:#206ab7;
  font-size:18px;
  line-height: 36px;
}
.index_icon{
  width: 32px;
  height: 32px;
  display: inline-block;
  vertical-align: middle;
  margin-right: 10px;
}
.index_icon_cygn{
  background:url(../assets/index_icon_cygn.png);
}
.index_icon_ywbl{
  background:url(../assets/index_icon_ywbl.png);
}
.index_icon_sjtj{
  background:url(../assets/index_icon_sjtj.png);
}
.index_icon_xtgg{
  background:url(../assets/index_icon_xtgg.png);
}
.list_cygn{
  width: 100%;
  margin:0 auto;
  overflow: hidden;
}
.list_cygn li{
  list-style: none;
  padding: 0;
  margin:0;
  float:left;
  width: 15%;
  text-align: center;
  margin-bottom: 100px;
}
.list_cygn li a{
  display: block;
  padding-top: 100px;
  text-decoration: none;
  color: #000;
  font-size:18px;
}
.list_cygn li a:hover{
  color:#f60;
}
.list_cygn_1{
  background: url(../assets/cy_icon_jgbz.png) no-repeat top center;
}
.list_cygn_2{
  background: url(../assets/cy_icon_gbxx.png) no-repeat top center;
}
.list_cygn_3{
  background: url(../assets/cy_icon_mcgl.png) no-repeat top center;
  background: url(../assets/checklist.png) no-repeat top center;
}
.list_cygn_4{
  background: url(../assets/cy_icon_mzshh.png) no-repeat top center;
}
.list_cygn_5{
  background: url(../assets/cy_icon_selection.png) no-repeat top center;
}
.list_cygn_6{
  background: url(../assets/cy_icon_mcgl.png) no-repeat top center;
}
.list_cygn_7{
  background: url(../assets/cy_icon_meeting.png) no-repeat top center;
}
.list_cygn_8{
  background: url(../assets/cy_icon_org.png) no-repeat top center;
}
h1{
  clear:both;
}
.list_ywbl{
  width: 600px;
  margin:0 auto;
  overflow: hidden;
}
.list_ywbl li{
  width:150px;
  height:80px;
  -webkit-border-radius: 5px;
  border-radius: 5px;
  -moz-border-radius: 5px;
  float:left;
  list-style: none;
  margin: 20px 40px;
  display: inline;
  padding:10px;
  text-align: center;
}
.list_ywbl li{
  cursor: pointer;
  font-size:14px;
  font-weight: bolder;
  color: #fff;
  text-decoration: none;
}
.list_ywbl li:hover{
  opacity: .6;
}
.list_ywbl li div{
  font-size: 50px;
  text-align: center;
}
.list_ywbl_1{
  background:#91c7ae;
}
.list_ywbl_2{
  background:#c23531;
}
.list_ywbl_3{
  background:#2f4554;
}
.list_ywbl_4{
  background:#61a0a8;
}
.list_ywbl_5{
  background:#d48265;
}
a{
  text-decoration: none;
  color: #204F7F
}
a:hover{
  text-decoration:underline;
  color: #f60;
}
.indexchart {
    -webkit-border-radius: 2px;
    border-radius: 2px;
    background-color: #f9f9f9;
    -webkit-box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    margin: 0 auto;
    padding:10px;
}
.docsearch{
  float:right;
  font-weight: normal;
  font-size:var(--size14);
  padding-right:10px;
}
</style>
<style>
#home_selection .el-badge__content.is-fixed{
  top: 12px; right: -3px;
}
.oneline .cell{
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  -o-text-overflow:ellipsis;
}
</style>
